home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / Demos / Duel / dsutil.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-31  |  5.5 KB  |  153 lines

  1. //-----------------------------------------------------------------------------
  2. // File: dsutil.cpp
  3. //
  4. // Desc: Routines for dealing with sounds from resources
  5. //
  6. // Copyright (C) 1995-2001 Microsoft Corporation. All Rights Reserved.
  7. //-----------------------------------------------------------------------------
  8. #ifndef DSUTIL_H
  9. #define DSUTIL_H
  10.  
  11.  
  12.  
  13.  
  14. //-----------------------------------------------------------------------------
  15. // Helper routines
  16. //-----------------------------------------------------------------------------
  17. HRESULT DSUtil_FillSoundBuffer( LPDIRECTSOUNDBUFFER pDSB, BYTE* pbWaveData,
  18.                                 DWORD dwWaveSize );
  19. HRESULT DSUtil_ParseWaveResource( VOID* pvRes, WAVEFORMATEX** ppWaveHeader,
  20.                                   BYTE** ppbWaveData, DWORD* pdwWaveSize );
  21.  
  22.  
  23.  
  24.  
  25. //-----------------------------------------------------------------------------
  26. // Name: DSUtil_LoadSoundBuffer()
  27. // Desc: Loads an IDirectSoundBuffer from a Win32 resource in the current
  28. //       application.
  29. //-----------------------------------------------------------------------------
  30. LPDIRECTSOUNDBUFFER DSUtil_LoadSoundBuffer( LPDIRECTSOUND* pDS,
  31.                                             LPCTSTR strName );
  32.  
  33.  
  34.  
  35.  
  36. //-----------------------------------------------------------------------------
  37. // Name: DSUtil_ReloadSoundBuffer()
  38. // Desc: Reloads an IDirectSoundBuffer from a Win32 resource in the current
  39. //       application. normally used to handle a DSERR_BUFFERLOST error.
  40. //-----------------------------------------------------------------------------
  41. HRESULT DSUtil_ReloadSoundBuffer( LPDIRECTSOUNDBUFFER pDSB, LPCTSTR strName );
  42.  
  43.  
  44.  
  45.  
  46. //-----------------------------------------------------------------------------
  47. // Name: DSUtil_GetWaveResource()
  48. // Desc: Finds a WAV resource in a Win32 module.
  49. //-----------------------------------------------------------------------------
  50. HRESULT DSUtil_GetWaveResource( HMODULE hModule, LPCTSTR strName,
  51.                                 WAVEFORMATEX** ppWaveHeader, BYTE** ppbWaveData,
  52.                                 DWORD* pdwWaveSize );
  53.  
  54.  
  55.  
  56.  
  57. //-----------------------------------------------------------------------------
  58. // Name: DSUtil_InitDirectSound()
  59. // Desc: 
  60. //-----------------------------------------------------------------------------
  61. HRESULT DSUtil_InitDirectSound( HWND hWnd );
  62.  
  63.  
  64.  
  65.  
  66. //-----------------------------------------------------------------------------
  67. // Name: DSUtil_FreeDirectSound()
  68. // Desc: 
  69. //-----------------------------------------------------------------------------
  70. VOID DSUtil_FreeDirectSound();
  71.  
  72.  
  73.  
  74.  
  75. //-----------------------------------------------------------------------------
  76. // Name: struct SoundObject
  77. // Desc: Used to manage individual sounds which need to be played multiple
  78. //       times concurrently.  A SoundObject represents a queue of
  79. //       IDirectSoundBuffer objects which all refer to the same buffer memory.
  80. //-----------------------------------------------------------------------------
  81. struct SoundObject
  82. {
  83.     BYTE* pbWaveData;                 // Ptr into wave resource (for restore)
  84.     DWORD cbWaveSize;                 // Size of wave data (for restore)
  85.     DWORD dwNumBuffers;               // Number of sound buffers.
  86.     DWORD dwCurrent;                  // Current sound buffer
  87.     LPDIRECTSOUNDBUFFER* pdsbBuffers; // List of sound buffers
  88. };
  89.  
  90.  
  91.  
  92.  
  93. //-----------------------------------------------------------------------------
  94. // Name: DSUtil_CreateSound()
  95. // Desc: Loads a SoundObject from a Win32 resource in the current application.
  96. //-----------------------------------------------------------------------------
  97. SoundObject* DSUtil_CreateSound( LPCTSTR strName, DWORD dwNumBuffers );
  98.  
  99.  
  100.  
  101.  
  102. //-----------------------------------------------------------------------------
  103. // Name: DSUtil_DestroySound()
  104. // Desc: Frees a SoundObject and releases all of its buffers.
  105. //-----------------------------------------------------------------------------
  106. VOID DSUtil_DestroySound( SoundObject* pSound );
  107.  
  108.  
  109.  
  110.  
  111. //-----------------------------------------------------------------------------
  112. // Name: DSUtil_PlayPannedSound()
  113. // Desc: Play a sound, but first set the panning according to where the
  114. //       object is on the screen. fScreenXPos is between -1.0f (left) and
  115. //       1.0f (right).
  116. //-----------------------------------------------------------------------------
  117. VOID DSUtil_PlayPannedSound( SoundObject* pSound, FLOAT fScreenXPos );
  118.  
  119.  
  120.  
  121.  
  122. //-----------------------------------------------------------------------------
  123. // Name: DSUtil_PlaySound()
  124. // Desc: Plays a buffer in a SoundObject.
  125. //-----------------------------------------------------------------------------
  126. HRESULT DSUtil_PlaySound( SoundObject* pSound, DWORD dwPlayFlags );
  127.  
  128.  
  129.  
  130.  
  131. //-----------------------------------------------------------------------------
  132. // Name: DSUtil_StopSound()
  133. // Desc: Stops one or more buffers in a SoundObject.
  134. //-----------------------------------------------------------------------------
  135. HRESULT DSUtil_StopSound( SoundObject* pSound );
  136.  
  137.  
  138.  
  139.  
  140. //-----------------------------------------------------------------------------
  141. // Name: DSUtil_GetFreeSoundBuffer()
  142. // Desc: Returns one of the cloned buffers that is not currently playing
  143. //-----------------------------------------------------------------------------
  144. LPDIRECTSOUNDBUFFER DSUtil_GetFreeSoundBuffer( SoundObject* pSound );
  145.  
  146.  
  147.  
  148.  
  149. #endif // DSUTIL_H
  150.  
  151.  
  152.  
  153.